﻿<?php
if(!defined('IN_PHPSCUP'))exit('hacking'); 

class LangApp extends BaseApp
{
    function index()
    {
	    $langdata = $GLOBALS['Lang']->_get_lang_typesdata();
		$this->assign('langdata', $langdata);
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('lang_sec.view.html');
    }


    function slist()
    {
		
		$v = $_GET['v'];
	    $v || $$v='languages';
	
	    $up_path = preg_replace("/(.*)\/([^\/]+)/is","\\1",$v);

		$lang_name_array = explode('/',$v);

	    $this_path = ROOT_PATH.'/languages/'.$v;
       
 
	    $lang_db = $this->get_file($v);	

        $this->assign('lang_name', $lang_name_array[0]);
        $this->assign('up_path', $up_path);
        $this->assign('this_path', $this_path);		
        $this->assign('lang_db', $lang_db);
		
			    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('lang_list.view.html');
    }



    function vlist($v = '')
    {
		
		$v || $v = $_GET['v'];
	    $v || $$v='languages';
	
	    $up_path = preg_replace("/(.*)\/([^\/]+)/is","\\1",$v);

	    $this_path = ROOT_PATH.'/languages/'.$v;
		
        $lang_db = array();
		
		if(is_file($this_path))
		{
           $lang_db = include($this_path);
		}
		else
		{
		   $lang_db = array();
		}


        $this->assign('v', $v);
        $this->assign('up_path', $up_path);
        $this->assign('this_path', $this_path);		
        $this->assign('lang_db', $lang_db);
		
			    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('lang_vlist.view.html');
    }


    function delvar()
    {
		
		$var = $_GET['var'];
		$file = $_GET['f'];
		

	    $this_path = ROOT_PATH.'/languages/'.$file;
		
        $lang_db = array();
		
		if(is_file($this_path))
		{
           $lang_db = include($this_path);
		}
		else
		{
		   $lang_db = array();
		}
        
		if(isset($lang_db[$var]))
		{
		   unset($lang_db[$var]);
		}
		$this->write_cache($this_path,$lang_db);
		
		$this->vlist($file);
    }


    function addvar()
    {
		
		$var = $_POST['var'];
		$val = $_POST['val'];
		$file = $_POST['file'];		

	    $this_path = ROOT_PATH.'/languages/'.$file;
		
        $lang_db = array();
		
		if(is_file($this_path))
		{
           $lang_db = include($this_path);
		}
		else
		{
		   $lang_db = array();
		}
        
		if(isset($lang_db[$var]))
		{
           $notice = &get_message(array('msg'=>'false!','url'=>'','title'=>'Notice'));
		   $notice ->display();
		   
		}else
		{
		   $lang_db[$var]=$val;
		
		}
		
		
		$this->write_cache($this_path,$lang_db);
		
		$this->vlist($file);
    }


    function editvar()
    {
		
		$var = $_POST['var'];
		$val = $_POST['v'];
		$file = $_POST['f'];		

	    $this_path = ROOT_PATH.'/languages/'.$file;
		
        $lang_db = array();
		
		if(is_file($this_path))
		{
           $lang_db = include($this_path);
		}
		else
		{
		   $lang_db = array();
		}
        
		if(isset($lang_db[$var]))
		{
		    $lang_db[$var]=$val;
			
		}else
		{
		  
		   $notice = &get_message(array('msg'=>'false!','url'=>'','title'=>'Notice'));
		   $notice ->display();
		
		}
		
		
		$this->write_cache($this_path,$lang_db);
		
		$this->vlist($file);
    }


    function get_file($dir)
	{
	    $dir_hand = opendir(ROOT_PATH.'/languages/'.$dir);
	    while($file=readdir($dir_hand))
	    {
		     $rs['path']="$dir/$file";
		    if(is_file(ROOT_PATH.'/languages/'."$dir/$file"))
		    {
			$rs['type']="file";
			$rs['icon']="data/images/file.gif";
			$array[]=$rs;
		    }
		    elseif( $file!="." && $file!=".." && is_dir(ROOT_PATH.'/languages/'."$dir/$file") )
		    {
			$rs['type']="dir";
			$rs['icon']="data/images/folder.gif";
			$array[]=$rs;
		    }
	    }
		if(!isset($array))
		{
		$array = array();
		}
	   return $array;
    }

    function write_cache($file,$data)
    {

	    write_file($file, "<?php if(!defined('IN_PHPSCUP'))exit('hacking');  \nreturn " . var_export($data , true) . ";\n?>");
		
		if(!is_writable($file))
		{
		exit('file directory is not writed power');//文件目录权限不可写
	    }


    }

}


?>